<template>
  <div>
    <div class="search">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="供应商">
          <el-input v-model="formData.supplier" placeholder="请输入供应商名称" />
        </el-form-item>
        <el-form-item label="订单编号">
          <el-input v-model="formData.ordercode" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="负责人">
          <el-input v-model="formData.username" placeholder="请输入负责人名字" />
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="formData.status" placeholder="请选择" @change="getdata">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getdata">查询</el-button>
        </el-form-item>
      </el-form>

    </div>

    <div>
      <el-table :data="tableData" border>
        <el-table-column prop="ordercode" label="订单号" />
        <el-table-column prop="account.username" label="负责人" />
        <el-table-column prop="object.name" label="供应商" />
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status==0" effect="dark" type="success">已处理</el-tag>
            <el-tag v-if="scope.row.status==1" effect="dark" type="info">未处理</el-tag>

          </template>

        </el-table-column>
        <el-table-column prop="details" label="订单详情">
          <template slot-scope="scope">
            <el-popover
              placement="right"
              width="400"
              trigger="click"
            >
              <el-table :data="scope.row.details">
                <el-table-column property="product.name" label="产品名" />
                <el-table-column property="product.brand" label="品牌" />
                <el-table-column property="product.model.info" label="产品类型" />
                <el-table-column property="quantity" label="数量" />
              </el-table>
              <el-button slot="reference">详情</el-button>
            </el-popover>

          </template>
        </el-table-column>
        <el-table-column prop="price" label="总额(元)" />
        <el-table-column prop="createTime" label="更新时间" />
      </el-table>
    </div>
    <div class="block">
      <el-pagination
        :page-size="limit"
        :total="total"
        style="padding:30px 0;text-align:center;"
        layout="total,prev,pager,next,jumper"
        @current-change="getPagedata"
      />
    </div>

  </div>
</template>

<script>
import orderApi from '@/api/order/order'
import supplierApi from '@/api/supplier/supplier'
export default {
  data() {
    return {
      formData: {

      },
      options: [
        {
          value: '-1',
          label: '全部'
        },
        {
          value: '0',
          label: '已处理'
        },
        {
          value: '1',
          label: '未处理'
        }],
      tableData: null,
      current: 1, // 当前页
      limit: 10, // 每页显示记录数
      total: 0, // 总记录数
      dialogVisible: false,

      allsupplier: null

    }
  },
  created() {
    this.formData.status = this.options[0].value
    this.getdata()
    this.getsupplier()
  },
  methods: {

    getsupplier() {
      supplierApi.getAllsupplier().then(res => {
        this.allsupplier = res.data
      })
    },

    // 获取数据
    getdata() {
      this.formData.page = this.current
      this.formData.limit = this.limit
      orderApi.showpurchase(this.formData).then(
        res => {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      )
    },
    getPagedata(page = 1) {
      this.current = page
      this.formData.page = this.current
      this.formData.limit = this.limit
      orderApi.showpurchase(this.formData).then(
        res => {
          this.tableData = res.data.list
          this.total = res.data.total
        }
      )
    }
  }
}
</script>

<style scoped lang="scss">

</style>

